package com.unidt.www.framework.common.util.number;

import lombok.Data;
import org.apache.commons.lang3.StringUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author sk
 * @Description:
 * @Date 2022/12/9 16:54
 **/
@Data
public class OrganIdUtils {

    public  static List<Long> getAllOrganIds(Long organId){

        List<Long> ids  = new ArrayList<>();
        String  organIdStr = String.valueOf(organId);
        addCode(ids,getProvince(organIdStr));
        addCode(ids,getCity(organIdStr));
        addCode(ids,getCounty(organIdStr));
        addCode(ids,getTown(organIdStr));
        addCode(ids,getVillage(organIdStr));
        return ids;
    }

    public static String getProvince(String organIdStr){
        return NumberUtils.left(organIdStr,2);
    }

    public static String getCity(String organIdStr){
        return NumberUtils.left(organIdStr,4);
    }

    public static String getCounty(String organIdStr){
        return NumberUtils.left(organIdStr,6);
    }

    public static String getTown(String organIdStr){
        return NumberUtils.left(organIdStr,9);
    }

    public static String getVillage(String organIdStr){
        return NumberUtils.left(organIdStr,12);
    }


    private static void addCode(List<Long> codes,String organCode){
        if(StringUtils.isNotBlank(organCode)){
            codes.add(Long.valueOf(organCode));
        }
    }

    public static void main(String[] args) {
       List<Long> ids =   getAllOrganIds(331181207232L);
        System.out.println(ids);
    }

}
